package dhm.com.hpx.activity;

import android.Manifest;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.drawable.BitmapDrawable;
import android.location.Location;
import android.os.Looper;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.amap.api.maps2d.AMap;
import com.amap.api.maps2d.CameraUpdateFactory;
import com.amap.api.maps2d.LocationSource;
import com.amap.api.maps2d.MapView;
import com.amap.api.maps2d.model.BitmapDescriptor;
import com.amap.api.maps2d.model.BitmapDescriptorFactory;
import com.amap.api.maps2d.model.CircleOptions;
import com.amap.api.maps2d.model.LatLng;
import com.amap.api.maps2d.model.LatLngBounds;
import com.amap.api.maps2d.model.Marker;
import com.amap.api.maps2d.model.MarkerOptions;
import com.amap.api.maps2d.model.MyLocationStyle;
import com.amap.api.services.core.AMapException;
import com.amap.api.services.core.LatLonPoint;
import com.amap.api.services.core.PoiItem;
import com.amap.api.services.core.ServiceSettings;
import com.amap.api.services.core.SuggestionCity;
import com.amap.api.services.poisearch.PoiResult;
import com.amap.api.services.poisearch.PoiSearch;
import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.search.core.CityInfo;
import com.baidu.mapapi.search.core.PoiInfo;
import com.baidu.mapapi.search.core.SearchResult;
import com.baidu.mapapi.search.poi.OnGetPoiSearchResultListener;
import com.baidu.mapapi.search.poi.PoiCitySearchOption;
import com.baidu.mapapi.search.poi.PoiDetailResult;
import com.baidu.mapapi.search.poi.PoiDetailSearchResult;
import com.baidu.mapapi.search.poi.PoiIndoorResult;
import com.baidu.mapapi.search.poi.PoiNearbySearchOption;
import com.baidu.mapapi.search.sug.OnGetSuggestionResultListener;
import com.baidu.mapapi.search.sug.SuggestionResult;
import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.tencent.lbssearch.TencentSearch;
import com.tencent.lbssearch.httpresponse.BaseObject;
import com.tencent.lbssearch.httpresponse.HttpResponseListener;
import com.tencent.lbssearch.object.param.SearchParam;
import com.tencent.lbssearch.object.result.SearchResultObject;
import com.tencent.map.geolocation.TencentLocation;
import com.tencent.map.geolocation.TencentLocationListener;
import com.tencent.map.geolocation.TencentLocationManager;
import com.tencent.map.geolocation.TencentLocationRequest;
import com.tencent.tencentmap.mapsdk.maps.CameraUpdate;
import com.tencent.tencentmap.mapsdk.maps.TencentMap;
import com.tencent.tencentmap.mapsdk.maps.UiSettings;
import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import dhm.com.hpx.R;
import dhm.com.hpx.adapter.PoiListAdapter;
import dhm.com.hpx.adapter.TradesAdapter;
import dhm.com.hpx.base.BaseActivity;
import dhm.com.hpx.base.Presenter.PressenterImpl;
import dhm.com.hpx.base.netWork.Constant;
import dhm.com.hpx.base.netWork.LoginContract;
import dhm.com.hpx.entity.Bean;
import dhm.com.hpx.entity.GetTradesBean;
import dhm.com.hpx.entity.Houtai;
import dhm.com.hpx.entity.PoiProvince;
import dhm.com.hpx.utils.GetJsonDataUtil;
import dhm.com.hpx.utils.SpUtils;
import dhm.com.hpx.utils.mapapi.overlayutil.PoiOverlay;
import pub.devrel.easypermissions.EasyPermissions;

public class MapsActivity extends BaseActivity implements AMap.OnMyLocationChangeListener, PoiSearch.OnPoiSearchListener, LocationSource,
        AMapLocationListener, LoginContract.IView, OnGetPoiSearchResultListener,
        OnGetSuggestionResultListener, AdapterView.OnItemClickListener, PoiListAdapter.OnGetChildrenLocationListener, com.tencent.tencentmap.mapsdk.maps.LocationSource, TencentMap.OnMapLongClickListener, TencentLocationListener {

    MapView mMapView = null;

    MyLocationStyle myLocationStyle;
    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.text_map)
    TextView text_map;
    @BindView(R.id.bmapView)
    com.baidu.mapapi.map.MapView bmapView;
    @BindView(R.id.tencentmap)
    com.tencent.tencentmap.mapsdk.maps.MapView tengxuntMap;

    @BindView(R.id.quantu)
    RadioButton quantu;
    @BindView(R.id.fenlei)
    RadioButton fenlei;
    @BindView(R.id.fanwei)
    RadioButton fanwei;
    @BindView(R.id.source_check)
    RadioGroup sourceCheck;
    @BindView(R.id.edit_quantu)
    EditText editQuantu;
    @BindView(R.id.edit_fanwei)
    EditText edit_fanwei;
    @BindView(R.id.text_hang)
    TextView textHang;
    @BindView(R.id.chengshi)
    TextView chengshi;
    @BindView(R.id.text_fjuli)
    TextView textFjuli;
    @BindView(R.id.text_fhang)
    TextView textFhang;
    @BindView(R.id.lin_fanwei)
    LinearLayout linFanwei;
    @BindView(R.id.lin_fenlei)
    LinearLayout linFenlei;
    @BindView(R.id.addr)
    LinearLayout addr;
    @BindView(R.id.get_num)
    TextView getNum;
    @BindView(R.id.quan)
    ImageView quan;
    @BindView(R.id.def_no)
    ImageView defNo;
    @BindView(R.id.def_yes)
    ImageView defYes;
    @BindView(R.id.start)
    Button start;
    @BindView(R.id.gaode)
    RadioButton gaode;
    @BindView(R.id.baidu)
    RadioButton baidu;
    @BindView(R.id.tengxun)
    RadioButton tengxun;
    @BindView(R.id.check_type)
    RadioGroup checkType;

    private OptionsPickerView pvOptions;


    private List<PoiProvince.DataBean> options1Items = new ArrayList<>(); //省
    private ArrayList<String> optionshItems = new ArrayList<>();
    private ArrayList<ArrayList<String>> options2Items = new ArrayList<>();//市
    private ArrayList<ArrayList<ArrayList<String>>> options3Items = new ArrayList<>();//区

    private String province = "";
    private String city = "";
    private String area = "";
    private String citycode = "110000";


    private boolean isDef = false;
    /**
     * 1高德
     * 2百度
     * 3腾讯
     */
    private int maptype = 1;
    /**
     * 1全图客源
     * 2分类客源
     * 3范围客源
     */
    private int findtype = 1;
    private List<GetTradesBean.DataBean> getTradesBean = new ArrayList<>();
    private List<GetTradesBean.DataBean> getTradesBeans = new ArrayList<>();

    private PressenterImpl pressenter;


    /**
     * 百度地图
     */
    private BaiduMap mBaiduMap = null;
    private com.baidu.mapapi.search.poi.PoiSearch mPoiSearch = null;
    private com.baidu.mapapi.map.BitmapDescriptor mBitmap = com.baidu.mapapi.map.BitmapDescriptorFactory.fromResource(R.drawable.icon_gcoding);


    /**
     * 腾讯地图
     */
    protected UiSettings mapUiSettings;
    private TencentMap tencentMap;
    private TencentLocationManager locationManager;
    private TencentLocationRequest locationRequest;
    private com.tencent.tencentmap.mapsdk.maps.model.MyLocationStyle locationStyle;
    private com.tencent.tencentmap.mapsdk.maps.LocationSource.OnLocationChangedListener locationChangedListener;





    private String uid;
    private String locationCode;


    @Override
    protected int getLayout() {
        return R.layout.activity_maps;
    }

    AMap aMap;

    @Override
    public void onMyLocationChange(Location location) {

    }

    @Override
    protected void initView() {
        ButterKnife.bind(this);
        ServiceSettings.updatePrivacyShow(MapsActivity.this,true,true);
        ServiceSettings.updatePrivacyAgree(MapsActivity.this,true);

        //定位需要申请的权限
        String[] perms = {
                Manifest.permission.ACCESS_FINE_LOCATION,
                Manifest.permission.ACCESS_COARSE_LOCATION,
                Manifest.permission.READ_PHONE_STATE
        };

        if (EasyPermissions.hasPermissions(this, perms)) {//检查是否获取该权限
            Log.i("location", "已获取权限");
        } else {
            EasyPermissions.requestPermissions(this, "必要的权限", 0, perms);
        }
        pressenter = new PressenterImpl();
        pressenter.attachView(this);
        mBaiduMap = bmapView.getMap();
        // 创建poi检索实例，注册搜索事件监听
        mPoiSearch = com.baidu.mapapi.search.poi.PoiSearch.newInstance();
        mPoiSearch.setOnGetPoiSearchResultListener(this);

        tencentMap = tengxuntMap.getMap();
        mapUiSettings = tencentMap.getUiSettings();


       //设置显示定位的图标
        mapUiSettings.setMyLocationButtonEnabled(true);
        tencentMap.setOnMapLongClickListener(this);


        locationStyle = new com.tencent.tencentmap.mapsdk.maps.model.MyLocationStyle();
        //创建图标
//        com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptor bitmapDescriptor = com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory.fromBitmap(getBitMap(R.drawable.location_icon));
//        locationStyle.icon(bitmapDescriptor);
        //设置定位圆形区域的边框宽度
        locationStyle.strokeWidth(3);
        //设置圆区域的颜色
        locationStyle.fillColor(R.color.style);
        locationStyle = locationStyle.myLocationType(com.tencent.tencentmap.mapsdk.maps.model.MyLocationStyle.LOCATION_TYPE_MAP_ROTATE_NO_CENTER);

        //建立定位
        initLocation();


        //SDK版本4.3.5新增内置定位标点击回调监听
        tencentMap.setMyLocationClickListener(new TencentMap.OnMyLocationClickListener() {
            @Override
            public boolean onMyLocationClicked(com.tencent.tencentmap.mapsdk.maps.model.LatLng latLng) {
                Toast.makeText(MapsActivity.this, "内置定位标点击回调", Toast.LENGTH_SHORT).show();
                return true;
            }
        });
        tencentMap.setBuildingEnable(false);

        uid = SpUtils.getString(this, "uid");


        String type = getIntent().getStringExtra("type");
        switch (type) {
            case "1":
                findtype = 1;
                title.setText("全图客源");
                editQuantu.setVisibility(View.VISIBLE);
                linFenlei.setVisibility(View.GONE);
                linFanwei.setVisibility(View.GONE);
                quantu.setChecked(true);
                break;
            case "2":
                findtype = 2;
                title.setText("分类客源");
                editQuantu.setVisibility(View.GONE);
                linFenlei.setVisibility(View.VISIBLE);
                linFanwei.setVisibility(View.GONE);
                fenlei.setChecked(true);
                break;
            case "3":
                findtype = 3;
                title.setText("范围客源");
                editQuantu.setVisibility(View.GONE);
                linFenlei.setVisibility(View.GONE);
                linFanwei.setVisibility(View.VISIBLE);
                fanwei.setChecked(true);
             /*   try {
                    Geocoder geo = new Geocoder(this, Locale.getDefault());
                    if (geo==null){
                        Toast.makeText(MapsActivity.this, "获取定位失败", Toast.LENGTH_SHORT).show();
                        return;
                    }else {
                        Toast.makeText(MapsActivity.this, "geo不为空", Toast.LENGTH_SHORT).show();
                    }
                    List<Address> addresses = geo.getFromLocation(lp.getLatitude(), lp.getLongitude(), 1);
                    if (addresses==null||addresses.size()==0){
                        Toast.makeText(this, "获取定位失败", Toast.LENGTH_SHORT).show();
                        return;
                    }else {
                        Toast.makeText(this, "addresses不为空", Toast.LENGTH_SHORT).show();
                    }
                    if (addresses.get(0).getLocality()==null){
                        Toast.makeText(this, "获取定位失败", Toast.LENGTH_SHORT).show();
                        return;
                    }else {
                        Toast.makeText(this, "province不为空", Toast.LENGTH_SHORT).show();
                    }
                    if (addresses.get(0).getAdminArea()==null){
                        Toast.makeText(this, "获取定位失败", Toast.LENGTH_SHORT).show();
                        return;
                    }else {
                        Toast.makeText(this, "city不为空", Toast.LENGTH_SHORT).show();
                    }
                    if (addresses.get(0).getSubLocality()==null){
                        Toast.makeText(this, "获取定位失败", Toast.LENGTH_SHORT).show();
                        return;
                    }else {
                        Toast.makeText(this, "area不为空", Toast.LENGTH_SHORT).show();
                    }
                    chengshi.setText(addresses.get(0).getLocality() + addresses.get(0).getAdminArea() + addresses.get(0).getSubLocality());
                    province = addresses.get(0).getLocality();
                    city = addresses.get(0).getAdminArea();
                    area = addresses.get(0).getSubLocality();
                } catch (IOException e) {
                    e.printStackTrace();
                }*/
                break;
            default:
        }


        //获取地图控件引用
        mMapView = (MapView) findViewById(R.id.map);
        //在activity执行onCreate时执行mMapView.onCreate(savedInstanceState)，创建地图
        mMapView.onCreate(this.savedInstanceState);
//初始化地图控制器对象
        if (aMap == null) {
            aMap = mMapView.getMap();
        }


        // 自定义系统定位小蓝点
        MyLocationStyle myLocationStyle = new MyLocationStyle();
        myLocationStyle.myLocationIcon(BitmapDescriptorFactory
                .fromResource(R.drawable.location_marker));// 设置小蓝点的图标
        myLocationStyle.strokeColor(Color.BLACK);// 设置圆形的边框颜色
        myLocationStyle.radiusFillColor(Color.argb(100, 0, 0, 180));// 设置圆形的填充颜色
        // myLocationStyle.anchor(int,int)//设置小蓝点的锚点
        myLocationStyle.strokeWidth(0f);// 设置圆形的边框粗细
        aMap.setMyLocationStyle(myLocationStyle);
        aMap.setLocationSource(this);// 设置定位监听
        aMap.getUiSettings().setMyLocationButtonEnabled(true);// 设置默认定位按钮是否显示
        aMap.setMyLocationEnabled(true);// 设置为true表示显示定位层并可触发定位，false表示隐藏定位层并不可触发定位，默认是false


        checkType.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                switch (i) {
                    case R.id.gaode:
                        maptype = 1;
                        bmapView.setVisibility(View.VISIBLE);
                        tengxuntMap.setVisibility(View.VISIBLE);
                        mMapView.setVisibility(View.VISIBLE);
//                        Toast.makeText(MapsActivity.this, "高德地图", Toast.LENGTH_SHORT).show();
                        break;
                    case R.id.baidu:
                        maptype = 2;
                        tengxuntMap.setVisibility(View.GONE);
                        mMapView.setVisibility(View.VISIBLE);
                        mMapView.setVisibility(View.GONE);
                        bmapView.setVisibility(View.VISIBLE);
//                        Toast.makeText(MapsActivity.this, "百度地图", Toast.LENGTH_SHORT).show();
                        break;
                    case R.id.tengxun:
                        maptype = 3;
                        bmapView.setVisibility(View.VISIBLE);
                        mMapView.setVisibility(View.VISIBLE);
                        mMapView.setVisibility(View.GONE);
                        tengxuntMap.setVisibility(View.VISIBLE);
//                        Toast.makeText(MapsActivity.this, "腾讯地图", Toast.LENGTH_SHORT).show();

                        break;
                    default:
                }
            }
        });

        sourceCheck.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                switch (i) {
                    case R.id.quantu:
                        findtype = 1;
                        title.setText("全图客源");
                        editQuantu.setVisibility(View.VISIBLE);
                        linFenlei.setVisibility(View.GONE);
                        linFanwei.setVisibility(View.GONE);
                        addr.setClickable(true);
                        break;
                    case R.id.fenlei:
                        findtype = 2;
                        title.setText("分类客源");
                        editQuantu.setVisibility(View.GONE);
                        linFenlei.setVisibility(View.VISIBLE);
                        linFanwei.setVisibility(View.GONE);
                        addr.setClickable(true);
                        break;
                    case R.id.fanwei:
                        findtype = 3;
                        title.setText("范围客源");
                        editQuantu.setVisibility(View.GONE);
                        linFenlei.setVisibility(View.GONE);
                        linFanwei.setVisibility(View.VISIBLE);
                        addr.setClickable(false);
                       /* try {
                            Geocoder geo = new Geocoder(MapsActivity.this, Locale.getDefault());
                            if (geo==null){
                                Toast.makeText(MapsActivity.this, "获取定位失败", Toast.LENGTH_SHORT).show();
                                return;
                            }else {
                                Toast.makeText(MapsActivity.this, "geo不为空", Toast.LENGTH_SHORT).show();
                            }
                            List<Address> addresses = geo.getFromLocation(lp.getLatitude(), lp.getLongitude(), 1);
                            if (addresses==null||addresses.size()==0){
                                Toast.makeText(MapsActivity.this, "获取定位失败", Toast.LENGTH_SHORT).show();
                                return;
                            }else {
                                Toast.makeText(MapsActivity.this, "addresses不为空", Toast.LENGTH_SHORT).show();
                            }
                            if (addresses.get(0).getLocality()==null){
                                Toast.makeText(MapsActivity.this, "获取定位失败", Toast.LENGTH_SHORT).show();
                                return;
                            }else {
                                Toast.makeText(MapsActivity.this, "province不为空", Toast.LENGTH_SHORT).show();
                            }
                            if (addresses.get(0).getAdminArea()==null){
                                Toast.makeText(MapsActivity.this, "获取定位失败", Toast.LENGTH_SHORT).show();
                                return;
                            }else {
                                Toast.makeText(MapsActivity.this, "city不为空", Toast.LENGTH_SHORT).show();
                            }
                            if (addresses.get(0).getSubLocality()==null){
                                Toast.makeText(MapsActivity.this, "获取定位失败", Toast.LENGTH_SHORT).show();
                                return;
                            }else {
                                Toast.makeText(MapsActivity.this, "area不为空", Toast.LENGTH_SHORT).show();
                            }

                            chengshi.setText(addresses.get(0).getLocality() + addresses.get(0).getAdminArea() + addresses.get(0).getSubLocality());
                            province = addresses.get(0).getLocality();
                            city = addresses.get(0).getAdminArea();
                            area = addresses.get(0).getSubLocality();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }*/
                        break;
                    default:
                }

            }
        });

        initJsonData();

        HashMap<String, String> map = new HashMap<>();
        map.put("token", Constant.TOKEN);
        pressenter.sendMessage(this, Constant.trades_list, map, GetTradesBean.class);

    }

    @Override
    protected void initData() {


    }


    private Bitmap getBitMap(int resourceId) {
        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resourceId);
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        int newWidth = 55;
        int newHeight = 55;
        float widthScale = ((float) newWidth) / width;
        float heightScale = ((float) newHeight) / height;
        Matrix matrix = new Matrix();
        matrix.postScale(widthScale, heightScale);
        bitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
        return bitmap;
    }



    @Override
    protected void onStart() {
        super.onStart();
        tengxuntMap.onStart();
    }
/*

    */
/**
     * 定位的一些初始化设置
     */

    private void initLocation() {
        //用于访问腾讯定位服务的类, 周期性向客户端提供位置更新
        locationManager = TencentLocationManager.getInstance(this);
        //设置坐标系
        locationManager.setCoordinateType(TencentLocationManager.COORDINATE_TYPE_GCJ02);
        //创建定位请求
        locationRequest = TencentLocationRequest.create();
        //设置定位周期（位置监听器回调周期）为3s
        locationRequest.setInterval(3000);

        //地图上设置定位数据源
        tencentMap.setLocationSource(this);
        //设置当前位置可见
        tencentMap.setMyLocationEnabled(true);
        //设置定位图标样式
        // setLocMarkerStyle();
        tencentMap.setMyLocationStyle(locationStyle);
    }


    boolean isPOI=true;

    /**
     * 显示进度框
     */
    private void showProgressDialog() {
        if (progDialog == null) {
            progDialog = new ProgressDialog(this);
        }
        progDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        progDialog.setIndeterminate(false);
        progDialog.setCancelable(true);
        progDialog.setMessage("正在搜索...");
        progDialog.show();

        progDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialogInterface) {
                isPOI=false;
            }
        });

    }

    /**
     * 隐藏进度框
     */
    private void dissmissProgressDialog() {
        if (progDialog != null) {
            progDialog.dismiss();
        }
    }


    private ProgressDialog progDialog = null;// 搜索时进度条

    @OnClick({R.id.back, R.id.manage, R.id.addr, R.id.lin_fenlei, R.id.lin_fjuli, R.id.lin_fhang, R.id.quan, R.id.start, R.id.mylocation})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.manage:
                Intent intent=new Intent(this,ManagerActivity.class);
                intent.putExtra("type",findtype+"");
                startActivity(intent);
                break;
            case R.id.mylocation:

                    chengshi.setText(amapLocations.getProvince() + amapLocations.getCity() + amapLocations.getDistrict());
                    province = amapLocations.getProvince();
                    city = amapLocations.getCity();
                    area = amapLocations.getDistrict();
                    citycode=locationCode;

                break;
            case R.id.addr:
                //选择地址
                pvOptions = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
                    @Override
                    public void onOptionsSelect(int options1, int options2, int options3, View v) {
                        //返回的分别是三个级别的选中位置
                        chengshi.setText(options1Items.get(options1).getName()
                                + options2Items.get(options1).get(options2)
                                + options3Items.get(options1).get(options2).get(options3));
                        province = options1Items.get(options1).getName();
                        city = options2Items.get(options1).get(options2);
                        area = options3Items.get(options1).get(options2).get(options3);

                        citycode=options1Items.get(options1).getChildren().get(options2).getChildren().get(options3).getCode();

                    }
                }).build();

                pvOptions.setPicker(optionshItems, options2Items, options3Items);//三级选择器
                pvOptions.show();
                break;
            case R.id.lin_fenlei:
                setBackgroundAlpha(0.5f);
                popupWindows.showAtLocation(view, Gravity.BOTTOM, 0, 0);
                break;
            case R.id.lin_fjuli:
                setBackgroundAlpha(0.5f);
                popWindow.showAtLocation(view, Gravity.BOTTOM, 0, 0);
                break;
            case R.id.lin_fhang:
                setBackgroundAlpha(0.5f);
                popupWindows.showAtLocation(view, Gravity.BOTTOM, 0, 0);
                break;
            case R.id.quan:
                if (isDef) {
                    text_map.setVisibility(View.GONE);
                    quan.setBackgroundResource(R.drawable.back_quan);
                    defNo.setVisibility(View.VISIBLE);
                    defYes.setVisibility(View.GONE);
                } else {
                    text_map.setVisibility(View.VISIBLE);
                    quan.setBackgroundResource(R.drawable.back_quans);
                    defYes.setVisibility(View.VISIBLE);
                    defNo.setVisibility(View.GONE);
                }
                isDef = !isDef;
                break;
            case R.id.start:
                isPOI=true;
                PoiSearch poiSearch;
                page=1;
                num=0;
                switch (maptype) {
                    case 1:
                        switch (sourceCheck.getCheckedRadioButtonId()) {
                            case R.id.quantu:
                                String s = editQuantu.getText().toString();
                                if (s == null || s.equals("")) {
                                    Toast.makeText(this, "请输入关键字", Toast.LENGTH_SHORT).show();
                                    return;
                                }
                                query = new PoiSearch.Query(s, "", citycode);
                                query.setPageSize(100000);// 设置每页最多返回多少条poiitem
                                query.setPageNum(page);//设置查询页码
                                query.setCityLimit(true);
                                try {
                                    poiSearch = new PoiSearch(this, query);
                                    poiSearch.setOnPoiSearchListener(this);
                                    poiSearch.searchPOIAsyn();
                                    showProgressDialog();
                                } catch (AMapException e) {
                                    e.printStackTrace();
                                }

                                break;
                            case R.id.fenlei:
                                String fenlei = textFhang.getText().toString();
                                if (fenlei == null || fenlei.equals("选择行业")) {
                                    Toast.makeText(this, "请选择行业", Toast.LENGTH_SHORT).show();
                                    return;
                                }
                                query = new PoiSearch.Query(fenlei, "",citycode);
                                query.setPageSize(100000);// 设置每页最多返回多少条poiitem
                                query.setPageNum(page);//设置查询页码
                                query.setCityLimit(true);
                                try {
                                    poiSearch = new PoiSearch(this, query);
                                    poiSearch.setOnPoiSearchListener(this);

                                    poiSearch.searchPOIAsyn();
                                    showProgressDialog();
                                } catch (AMapException e) {
                                    e.printStackTrace();
                                }
                                break;
                            case R.id.fanwei:
                                String fenleis = edit_fanwei.getText().toString();
                                if (check == 0) {
                                    Toast.makeText(this, "请选择范围", Toast.LENGTH_SHORT).show();
                                    return;
                                }
                                query = new PoiSearch.Query(fenleis, "", "");// 第一个参数表示搜索字符串，第二个参数表示poi搜索类型，第三个参数表示poi搜索区域（空字符串代表全国）
                                query.setPageSize(100000);// 设置每页最多返回多少条poiitem
                                query.setPageNum(page);// 设置查第一页
                                if (lp != null) {
                                    try {
                                        poiSearch = new PoiSearch(this, query);
                                        poiSearch.setOnPoiSearchListener(this);
                                        poiSearch.setBound(new PoiSearch.SearchBound(lp, check, true));//
                                        // 设置搜索区域为以lp点为圆心，其周围5000米范围
                                        poiSearch.searchPOIAsyn();// 异步搜索
                                        showProgressDialog();
                                    } catch (AMapException e) {
                                        e.printStackTrace();
                                    }
                                }
                                break;
                            default:
                        }
                        break;
                    case 2:
                        switch (sourceCheck.getCheckedRadioButtonId()) {
                            case R.id.quantu:
                                String s = editQuantu.getText().toString();
                                if (s == null || s.equals("")) {
                                    Toast.makeText(this, "请输入关键字", Toast.LENGTH_SHORT).show();
                                    return;
                                }
                                mPoiSearch.searchInCity((new PoiCitySearchOption())
                                        .city(province+city+area)
                                        .keyword(s)
                                        .pageNum(page) // 分页编号
                                        .cityLimit(true)
                                        .pageCapacity(10)
                                        .scope(2));
                                showProgressDialog();
                                break;
                            case R.id.fenlei:
                                String fenlei = textFhang.getText().toString();
                                if (fenlei == null || fenlei.equals("选择行业")) {
                                    Toast.makeText(this, "请选择行业", Toast.LENGTH_SHORT).show();
                                    return;
                                }

                                mPoiSearch.searchInCity((new PoiCitySearchOption())
                                        .city(province+city+area)
                                        .keyword(fenlei)
                                        .pageNum(page) // 分页编号
                                        .cityLimit(true)
                                        .pageCapacity(10)
                                        .scope(2));
                                showProgressDialog();
                                break;
                            case R.id.fanwei:
                                String fenleis = edit_fanwei.getText().toString();
                                if (check == 0) {
                                    Toast.makeText(this, "请选择范围", Toast.LENGTH_SHORT).show();
                                    return;
                                }
                                com.baidu.mapapi.model.LatLng latLng = new com.baidu.mapapi.model.LatLng(lp.getLatitude(), lp.getLongitude());

                                // 配置请求参数
                                PoiNearbySearchOption nearbySearchOption = new PoiNearbySearchOption()
                                        .keyword(fenleis) // 检索关键字
                                        .location(latLng) // 经纬度
                                        .radius(check) // 检索半径 单位： m
                                        .pageNum(page) // 分页编号
                                        .radiusLimit(true)
                                        .pageCapacity(10)
                                        .scope(2);
                                // 发起检索
                                mPoiSearch.searchNearby(nearbySearchOption);
                                showProgressDialog();
                                break;
                            default:
                        }
                        break;
                    case 3:
                        switch (sourceCheck.getCheckedRadioButtonId()) {
                            case R.id.quantu:
                                String s = editQuantu.getText().toString();
                                if (s == null || s.equals("")) {
                                    Toast.makeText(this, "请输入关键字", Toast.LENGTH_SHORT).show();
                                    return;
                                }
                                page=1;
                                showProgressDialog();
                                searchPoiquantu(s);

                                break;
                            case R.id.fenlei:
                                String fenlei = textFhang.getText().toString();
                                if (fenlei == null || fenlei.equals("")) {
                                    Toast.makeText(this, "请选择行业", Toast.LENGTH_SHORT).show();
                                    return;
                                }
                                page=1;
                                showProgressDialog();
                                searchPoiquantu(fenlei);

                                break;
                            case R.id.fanwei:
                                String fenleis = edit_fanwei.getText().toString();
                                if (check == 0) {
                                    Toast.makeText(this, "请选择范围", Toast.LENGTH_SHORT).show();
                                    return;
                                }
                                page=1;
                                showProgressDialog();
                                searchPoifanwei(fenleis);

                                break;
                            default:
                        }
                        break;
                    default:
                }

                break;
            default:
        }
    }


    @Override
    protected void onResume() {
        super.onResume();
        //在activity执行onResume时执行mMapView.onResume ()，重新绘制加载地图
        mMapView.onResume();
        bmapView.onResume();
        tengxuntMap.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
        //在activity执行onPause时执行mMapView.onPause ()，暂停地图的绘制
        mMapView.onPause();
        bmapView.onPause();
        tengxuntMap.onPause();
    }

    @Override
    protected void onStop() {
        super.onStop();
        tengxuntMap.onStop();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        //在activity执行onDestroy时执行mMapView.onDestroy()，销毁地图
        mMapView.onDestroy();
        // 释放bitmap
        mBitmap.recycle();
        // 释放检索对象
        mPoiSearch.destroy();
        // 清空地图所有的覆盖物
        mBaiduMap.clear();
        // 释放地图组件
        bmapView.onDestroy();
        tengxuntMap.onDestroy();
    }


    private int[] markers = {R.drawable.poi_marker,
            R.drawable.poi_marker,
            R.drawable.poi_marker,
            R.drawable.poi_marker,
            R.drawable.poi_marker,
            R.drawable.poi_marker,
            R.drawable.poi_marker,
            R.drawable.poi_marker,
            R.drawable.poi_marker,
            R.drawable.poi_marker
    };

    private PoiResult poiResult; // poi返回的结果
    private List<PoiItem> poiItems;// poi数据
    private RelativeLayout mPoiDetail;
    private PoiSearch.Query query;// Poi查询条件类
    private Marker mlastMarker;
    private myPoiOverlay poiOverlay;// poi图层


    private LatLonPoint lp = new LatLonPoint(39.993167, 116.473274);//
    AMapLocation amapLocations;
    int num=0;

    @Override
    public void onPoiSearched(PoiResult result, int rcode) {
        if (rcode == AMapException.CODE_AMAP_SUCCESS) {
            if (result != null && result.getQuery() != null) {// 搜索poi的结果
                if (result.getQuery().equals(query)) {// 是否是同一条
                    poiResult = result;

                    for (int i = 0; i < poiResult.getPois().size(); i++) {
                        if (poiResult.getPois().get(i).getTel() == null || poiResult.getPois().get(i).getTel().equals("")) {
                            poiResult.getPois().remove(i);
                            i = i - 1;
                        }
                    }
                    num=num+poiResult.getPois().size();
                    getNum.setText("本次共获客"+num+"条");
                    poiItems = poiResult.getPois();// 取得第一页的poiitem数据，页数从数字0开始
                    List<SuggestionCity> suggestionCities = poiResult
                            .getSearchSuggestionCitys();// 当搜索不到poiitem数据时，会返回含有搜索关键字的城市信息
                    if (poiItems != null && poiItems.size() > 0) {
                        if (page==1){

                            //清除POI信息显示
//                        whetherToShowDetailInfo(false);
                            //并还原点击marker样式
                            if (mlastMarker != null) {
                                resetlastmarker();
                            }
                            //清理之前搜索结果的marker
                            if (poiOverlay != null) {
                                poiOverlay.removeFromMap();
                            }

                            aMap.clear();
                        }

                        poiOverlay = new myPoiOverlay(aMap, poiItems);
                        poiOverlay.addToMap();
                        poiOverlay.zoomToSpan();

                        aMap.addMarker(new MarkerOptions()
                                .anchor(0.5f, 0.5f)
                                .icon(BitmapDescriptorFactory
                                        .fromBitmap(BitmapFactory.decodeResource(
                                                getResources(), R.drawable.point4)))
                                .position(new LatLng(lp.getLatitude(), lp.getLongitude())));

                        aMap.addCircle(new CircleOptions()
                                .center(new LatLng(lp.getLatitude(),
                                        lp.getLongitude())).radius(0)
                                .strokeColor(Color.BLUE)
                                .fillColor(Color.argb(50, 1, 1, 1))
                                .strokeWidth(2));

                        ArrayList<Houtai> list = new ArrayList<>();
                        String s="";

                        for (int i = 0; i < poiItems.size(); i++) {
                            PoiItem poiItem = poiItems.get(i);

                            String snippet = poiItem.getSnippet();//地址
                            String title = poiItem.getTitle();//肯德基（板井路店）
                            String tel = poiItem.getTel();//固定电话
                            String[] split = tel.split(";");
                            for (int j = 0; j < split.length; j++) {

                                Houtai houtai = new Houtai();
                                houtai.setSnippet(snippet);
                                houtai.setTel(split[j]);
                                houtai.setTitle(title);
                                houtai.setSource("1");
                                list.add(houtai);
                            }
                        }
                        s = new Gson().toJson(list);
                        Map<String, String> map = new HashMap<>();
                        map.put("token", Constant.TOKEN);
                        map.put("customer_type", findtype + "");
                        map.put("collect_data", s);
                        map.put("uid", uid);
                        map.put("province", province);
                        map.put("city", city);
                        map.put("area", area);

                        switch (sourceCheck.getCheckedRadioButtonId()) {
                            case R.id.quantu:
                                String ss = editQuantu.getText().toString();
                                map.put("search_key", ss);
                                break;
                            case R.id.fenlei:
                                String fenlei = textFhang.getText().toString();
                                map.put("industry", fenlei);
                                break;
                            case R.id.fanwei:
                                String fenleis = edit_fanwei.getText().toString();//check
                                map.put("search_key", fenleis);
                                map.put("distance", check + "");
                                break;
                            default:
                        }
                        pressenter.sendMessage(this, Constant.customercollectadd, map, Bean.class);
                        if (isPOI&&(result!=null||result.getPois()!=null||result.getPois().size()>0)){
                            page++;
                            PoiSearch poiSearch;
                            switch (maptype) {
                                case 1:

                                    switch (sourceCheck.getCheckedRadioButtonId()) {
                                        case R.id.quantu:
                                            s = editQuantu.getText().toString();
                                            if (s == null || s.equals("")) {
                                                Toast.makeText(this, "请输入关键字", Toast.LENGTH_SHORT).show();
                                                return;
                                            }
                                            query = new PoiSearch.Query(s, "", citycode);
                                            query.setPageSize(100000);// 设置每页最多返回多少条poiitem
                                            query.setPageNum(page);//设置查询页码
                                            query.setCityLimit(true);
                                            try {
                                                poiSearch = new PoiSearch(this, query);
                                                poiSearch.setOnPoiSearchListener(this);

                                                poiSearch.searchPOIAsyn();
                                            } catch (AMapException e) {
                                                e.printStackTrace();
                                            }
                                            break;
                                        case R.id.fenlei:
                                            String fenlei = textFhang.getText().toString();
                                            if (fenlei == null || fenlei.equals("选择行业")) {
                                                Toast.makeText(this, "请选择行业", Toast.LENGTH_SHORT).show();
                                                return;
                                            }
                                            query = new PoiSearch.Query(fenlei, "", citycode);
                                            query.setPageSize(100000);// 设置每页最多返回多少条poiitem
                                            query.setPageNum(page);//设置查询页码
                                            query.setCityLimit(true);
                                            try {
                                                poiSearch = new PoiSearch(this, query);
                                                poiSearch.setOnPoiSearchListener(this);

                                                poiSearch.searchPOIAsyn();
                                            } catch (AMapException e) {
                                                e.printStackTrace();
                                            }
                                            break;
                                        case R.id.fanwei:
                                            String fenleis = edit_fanwei.getText().toString();
                                            if (check == 0) {
                                                Toast.makeText(this, "请选择范围", Toast.LENGTH_SHORT).show();
                                                return;
                                            }
                                            query = new PoiSearch.Query(fenleis, "", "");// 第一个参数表示搜索字符串，第二个参数表示poi搜索类型，第三个参数表示poi搜索区域（空字符串代表全国）
                                            query.setPageSize(100000);// 设置每页最多返回多少条poiitem
                                            query.setPageNum(page);// 设置查第一页
                                            if (lp != null) {
                                                try {
                                                    poiSearch = new PoiSearch(this, query);
                                                    poiSearch.setOnPoiSearchListener(this);
                                                    poiSearch.setBound(new PoiSearch.SearchBound(lp, check, true));//
                                                    // 设置搜索区域为以lp点为圆心，其周围5000米范围
                                                    poiSearch.searchPOIAsyn();// 异步搜索
                                                } catch (AMapException e) {
                                                    e.printStackTrace();
                                                }
                                            }
                                            break;
                                        default:
                                    }
                                    break;
                                case 2:
                                    switch (sourceCheck.getCheckedRadioButtonId()) {
                                        case R.id.quantu:
                                            s = editQuantu.getText().toString();
                                            if (s == null || s.equals("")) {
                                                Toast.makeText(this, "请输入关键字", Toast.LENGTH_SHORT).show();
                                                return;
                                            }
                                            mPoiSearch.searchInCity((new PoiCitySearchOption())
                                                    .city(province+city+area)
                                                    .keyword(s)
                                                    .pageNum(page) // 分页编号
                                                    .cityLimit(true)
                                                    .pageCapacity(10000)
                                                    .scope(2));
                                            break;
                                        case R.id.fenlei:
                                            String fenlei = textFhang.getText().toString();
                                            if (fenlei == null || fenlei.equals("选择行业")) {
                                                Toast.makeText(this, "请选择行业", Toast.LENGTH_SHORT).show();
                                                return;
                                            }

                                            mPoiSearch.searchInCity((new PoiCitySearchOption())
                                                    .city(province+city+area)
                                                    .keyword(fenlei)
                                                    .pageNum(page) // 分页编号
                                                    .cityLimit(true)
                                                    .pageCapacity(10000)
                                                    .scope(2));
                                            break;
                                        case R.id.fanwei:
                                            String fenleis = edit_fanwei.getText().toString();
                                            if (check == 0) {
                                                Toast.makeText(this, "请选择范围", Toast.LENGTH_SHORT).show();
                                                return;
                                            }
                                            com.baidu.mapapi.model.LatLng latLng = new com.baidu.mapapi.model.LatLng(lp.getLatitude(), lp.getLongitude());

                                            // 配置请求参数
                                            PoiNearbySearchOption nearbySearchOption = new PoiNearbySearchOption()
                                                    .keyword(fenleis) // 检索关键字
                                                    .location(latLng) // 经纬度
                                                    .radius(check) // 检索半径 单位： m
                                                    .pageNum(page) // 分页编号
                                                    .radiusLimit(true)
                                                    .pageCapacity(10000)
                                                    .scope(2);
                                            // 发起检索
                                            mPoiSearch.searchNearby(nearbySearchOption);
                                            break;
                                        default:
                                    }
                                    break;
                                case 3:
                                    switch (sourceCheck.getCheckedRadioButtonId()) {
                                        case R.id.quantu:
                                            s = editQuantu.getText().toString();
                                            if (s == null || s.equals("")) {
                                                Toast.makeText(this, "请输入关键字", Toast.LENGTH_SHORT).show();
                                                return;
                                            }

                                            break;
                                        case R.id.fenlei:
                                            String fenlei = textFhang.getText().toString();
                                            if (fenlei == null || fenlei.equals("")) {
                                                Toast.makeText(this, "请选择行业", Toast.LENGTH_SHORT).show();
                                                return;
                                            }

                                            break;
                                        case R.id.fanwei:
                                            String fenleis = edit_fanwei.getText().toString();
                                            if (check == 0) {
                                                Toast.makeText(this, "请选择范围", Toast.LENGTH_SHORT).show();
                                                return;
                                            }

                                            break;
                                        default:
                                    }
                                    break;
                                default:
                            }

                        }


                    } else if (suggestionCities != null
                            && suggestionCities.size() > 0) {
                        dissmissProgressDialog();
                        showSuggestCity(suggestionCities);
                    } else {
                        dissmissProgressDialog();
                        if (page==1){
                            Toast.makeText(this, "抱歉，我们没有检测到任何数据", Toast.LENGTH_SHORT).show();
                        }
                    }
                }
            } else {
                dissmissProgressDialog();
                if (page==1){
                    Toast.makeText(this, "抱歉，我们没有检测到任何数据", Toast.LENGTH_SHORT).show();
                }
            }
        }

    }

    @Override
    public void onPoiItemSearched(PoiItem poiItem, int i) {

    }

    private void whetherToShowDetailInfo(boolean isToShow) {
        if (isToShow) {
            mPoiDetail.setVisibility(View.VISIBLE);

        } else {
            mPoiDetail.setVisibility(View.GONE);

        }
    }


    /**
     * poi没有搜索到数据，返回一些推荐城市的信息
     */
    private void showSuggestCity(List<SuggestionCity> cities) {
        String infomation = "推荐城市\n";
        for (int i = 0; i < cities.size(); i++) {
            infomation += "城市名称:" + cities.get(i).getCityName() + "城市区号:"
                    + cities.get(i).getCityCode() + "城市编码:"
                    + cities.get(i).getAdCode() + "\n";
        }

    }


    // 将之前被点击的marker置为原来的状态
    private void resetlastmarker() {
        int index = poiOverlay.getPoiIndex(mlastMarker);
        mlastMarker.setIcon(BitmapDescriptorFactory.fromBitmap(
                BitmapFactory.decodeResource(getResources(), R.drawable.poi_marker)));
        mlastMarker = null;

    }
    private CameraUpdate cameraSigma;
    private LocationSource.OnLocationChangedListener mListener;

    @Override
    public void onLocationChanged(AMapLocation amapLocation) {
        if (mListener != null && amapLocation != null) {

            if (amapLocations==null){

//                Toast.makeText(this, amapLocation.getDistrict(), Toast.LENGTH_SHORT).show();
                chengshi.setText(amapLocation.getProvince() + amapLocation.getCity() + amapLocation.getDistrict());
                province = amapLocation.getProvince();
                city = amapLocation.getCity();
                area = amapLocation.getDistrict();
                citycode=amapLocation.getAdCode();
            }

            amapLocations=amapLocation;
            lp = new LatLonPoint(amapLocation.getLatitude(), amapLocation.getLongitude());
            if (amapLocation != null && amapLocation.getErrorCode() == 0) {
                // 显示系统小蓝点
                mListener.onLocationChanged(amapLocation);
                //对地图操作类进行操作
                if (cameraSigma==null){
                    cameraSigma =
                            com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory.newCameraPosition(new CameraPosition(
                                    new com.tencent.tencentmap.mapsdk.maps.model.LatLng(lp.getLatitude(),lp.getLongitude()),
                                    15,
                                    0f,
                                    0f));
                    //移动地图
                    tencentMap.moveCamera(cameraSigma);
                }

                locationCode = amapLocation.getAdCode();


            } else {
//                Toast.makeText(this, "定位失败1", Toast.LENGTH_SHORT).show();
//                String errText = "定位失败," + amapLocation.getErrorCode() + ": " + amapLocation.getErrorInfo();
//                Log.e("AmapErr", errText);
            }
        } else {
            Toast.makeText(this, "定位失败2", Toast.LENGTH_SHORT).show();
            String errText = "定位失败," + amapLocation.getErrorCode() + ": " + amapLocation.getErrorInfo();
            Log.e("AmapErr", errText);
        }
    }

    private AMapLocationClient mlocationClient;
    private AMapLocationClientOption mLocationOption;

    @Override
    public void activate(LocationSource.OnLocationChangedListener listener) {
        mListener = listener;
        if (mlocationClient == null) {
            try {
                mlocationClient = new AMapLocationClient(this);
            } catch (Exception e) {
                e.printStackTrace();
            }
            mLocationOption = new AMapLocationClientOption();
            //设置定位监听
            mlocationClient.setLocationListener(this);
            //设置为高精度定位模式
            mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
            //设置定位参数
            mlocationClient.setLocationOption(mLocationOption);
            // 此方法为每隔固定时间会发起一次定位请求，为了减少电量消耗或网络流量消耗，
            // 注意设置合适的定位时间的间隔（最小间隔支持为2000ms），并且在合适时间调用stopLocation()方法来取消定位请求
            // 在定位结束后，在合适的生命周期调用onDestroy()方法
            // 在单次定位情况下，定位无论成功与否，都无需调用stopLocation()方法移除请求，定位sdk内部会移除
            mlocationClient.startLocation();
        }
    }


    @Override
    public void activate(com.tencent.tencentmap.mapsdk.maps.LocationSource.OnLocationChangedListener onLocationChangedListener) {
        locationChangedListener = onLocationChangedListener;
        int err = locationManager.requestLocationUpdates(locationRequest, this, Looper.myLooper());
        switch (err) {
            case 1:
                Toast.makeText(this, "设备缺少使用腾讯定位服务需要的基本条件", Toast.LENGTH_SHORT).show();
                break;
            case 2:
                Toast.makeText(this, "manifest 中配置的 key 不正确", Toast.LENGTH_SHORT).show();
                break;
            case 3:
                Toast.makeText(this, "自动加载libtencentloc.so失败", Toast.LENGTH_SHORT).show();
                break;

            default:
                break;
        }


    }

    /**
     * 停止定位
     */
    @Override
    public void deactivate() {
        mListener = null;
        if (mlocationClient != null) {
            mlocationClient.stopLocation();
            mlocationClient.onDestroy();
        }
//        mlocationClient = null;
//        locationManager.removeUpdates(this);
//        locationManager = null;
//        locationRequest = null;
//        locationChangedListener = null;

    }

    @Override
    public void requesta(Object data) {
        if (data instanceof GetTradesBean) {
            GetTradesBean data1 = (GetTradesBean) data;
            if (data1.getCode() == 1) {
                for (int i = 0; i < data1.getData().size(); i++) {
                    if (i < 3) {
                        getTradesBean.add(data1.getData().get(i));
                    } else {
                        getTradesBeans.add(data1.getData().get(i));
                    }
                }

                showPopwindow();
                showPopwindows();
            }
            if (data instanceof Bean) {
                Bean bean = (Bean) data;
                Toast.makeText(this, bean.getMessage(), Toast.LENGTH_SHORT).show();
            }
        }
    }

    @Override
    public void fail(String error) {

    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

    }

    private int page=1;

    @Override
    public void onGetPoiResult(com.baidu.mapapi.search.poi.PoiResult result) {
        if (result == null || result.error == SearchResult.ERRORNO.RESULT_NOT_FOUND) {
            if (page==1){
                mBaiduMap.clear();
                Toast.makeText(this, "未找到结果", Toast.LENGTH_LONG).show();
            }
            dissmissProgressDialog();
            return;
        }

        if (result.error == SearchResult.ERRORNO.NO_ERROR) {
            if (page==1){
                mBaiduMap.clear();
            }

            int padding = 50;
            // 添加poi
            MyPoiOverlays overlay = new MyPoiOverlays(mBaiduMap);
            mBaiduMap.setOnMarkerClickListener(overlay);
            overlay.setData(result);
            overlay.addToMap();
            // 设置显示在规定宽高中的地图地理范围
            overlay.zoomToSpanPaddingBounds(padding, padding, padding, padding);



            List<PoiInfo> allPoi = result.getAllPoi();
            for (int i = 0; i < allPoi.size(); i++) {
                if (allPoi.get(i).getPhoneNum()==null||allPoi.get(i).getPhoneNum().equals("")){
                    allPoi.remove(i);
                    i=i-1;
                }
            }

            ArrayList<Houtai> list = new ArrayList<>();
            String s="";

            for (int i = 0; i < allPoi.size(); i++) {
                PoiInfo poiInfo = allPoi.get(i);
                String tel = poiInfo.getPhoneNum();//固定电话
                String snippet = poiInfo.getAddress();//地址
                String title = poiInfo.getName();//肯德基（板井路店）

                String[] split = tel.split(";");
                for (int j = 0; j < split.length; j++) {

                    Houtai houtai = new Houtai();
                    houtai.setSnippet(snippet);
                    houtai.setTel(split[j]);
                    houtai.setTitle(title);
                    houtai.setSource("1");
                    list.add(houtai);
                }

            }
            s = new Gson().toJson(list);

            Map<String, String> map = new HashMap<>();
            map.put("token", Constant.TOKEN);
            map.put("customer_type", findtype + "");
            map.put("collect_data", s);
            map.put("uid", uid);
            map.put("province", province);
            map.put("city", city);
            map.put("area", area);

            switch (sourceCheck.getCheckedRadioButtonId()) {
                case R.id.quantu:
                    String ss = editQuantu.getText().toString();
                    map.put("search_key", ss);
                    break;
                case R.id.fenlei:
                    String fenlei = textFhang.getText().toString();
                    map.put("industry", fenlei);
                    break;
                case R.id.fanwei:
                    String fenleis = edit_fanwei.getText().toString();//check
                    map.put("search_key", fenleis);
                    map.put("distance", check + "");
                    break;
                default:
            }

            pressenter.sendMessage(this, Constant.customercollectadd, map, Bean.class);
            num=num+result.getAllPoi().size();
            getNum.setText("本次共获客"+num+"条");


            if (isPOI&&(result!=null||result.getAllPoi()!=null||result.getAllPoi().size()>0)){
                page++;
                PoiSearch poiSearch;
                switch (maptype) {
                    case 1:
                        switch (sourceCheck.getCheckedRadioButtonId()) {
                            case R.id.quantu:
                                s = editQuantu.getText().toString();
                                if (s == null || s.equals("")) {
                                    Toast.makeText(this, "请输入关键字", Toast.LENGTH_SHORT).show();
                                    return;
                                }
                                query = new PoiSearch.Query(s, "", citycode);
                                query.setPageSize(100000);// 设置每页最多返回多少条poiitem
                                query.setPageNum(page);//设置查询页码
                                query.setCityLimit(true);
                                try {
                                    poiSearch = new PoiSearch(this, query);
                                    poiSearch.setOnPoiSearchListener(this);

                                    poiSearch.searchPOIAsyn();
                                } catch (AMapException e) {
                                    e.printStackTrace();
                                }
                                break;
                            case R.id.fenlei:
                                String fenlei = textFhang.getText().toString();
                                if (fenlei == null || fenlei.equals("选择行业")) {
                                    Toast.makeText(this, "请选择行业", Toast.LENGTH_SHORT).show();
                                    return;
                                }
                                query = new PoiSearch.Query(fenlei, "", citycode);
                                query.setPageSize(100000);// 设置每页最多返回多少条poiitem
                                query.setPageNum(page);//设置查询页码
                                query.setCityLimit(true);
                                try {
                                    poiSearch = new PoiSearch(this, query);
                                    poiSearch.setOnPoiSearchListener(this);

                                    poiSearch.searchPOIAsyn();
                                } catch (AMapException e) {
                                    e.printStackTrace();
                                }
                                break;
                            case R.id.fanwei:
                                String fenleis = edit_fanwei.getText().toString();
                                if (check == 0) {
                                    Toast.makeText(this, "请选择范围", Toast.LENGTH_SHORT).show();
                                    return;
                                }
                                query = new PoiSearch.Query(fenleis, "", "");// 第一个参数表示搜索字符串，第二个参数表示poi搜索类型，第三个参数表示poi搜索区域（空字符串代表全国）
                                query.setPageSize(100000);// 设置每页最多返回多少条poiitem
                                query.setPageNum(page);// 设置查第一页
                                if (lp != null) {
                                    try {
                                        poiSearch = new PoiSearch(this, query);
                                        poiSearch.setOnPoiSearchListener(this);
                                        poiSearch.setBound(new PoiSearch.SearchBound(lp, check, true));//
                                        // 设置搜索区域为以lp点为圆心，其周围5000米范围
                                        poiSearch.searchPOIAsyn();// 异步搜索
                                    } catch (AMapException e) {
                                        e.printStackTrace();
                                    }
                                }
                                break;
                            default:
                        }
                        break;
                    case 2:
                        switch (sourceCheck.getCheckedRadioButtonId()) {
                            case R.id.quantu:
                                s = editQuantu.getText().toString();
                                if (s == null || s.equals("")) {
                                    Toast.makeText(this, "请输入关键字", Toast.LENGTH_SHORT).show();
                                    return;
                                }
                                mPoiSearch.searchInCity((new PoiCitySearchOption())
                                        .city(province+city+area)
                                        .keyword(s)
                                        .pageNum(page) // 分页编号
                                        .cityLimit(true)
                                        .pageCapacity(10)
                                        .scope(2));
                                break;
                            case R.id.fenlei:
                                String fenlei = textFhang.getText().toString();
                                if (fenlei == null || fenlei.equals("选择行业")) {
                                    Toast.makeText(this, "请选择行业", Toast.LENGTH_SHORT).show();
                                    return;
                                }

                                mPoiSearch.searchInCity((new PoiCitySearchOption())
                                        .city(province+city+area)
                                        .keyword(fenlei)
                                        .pageNum(page) // 分页编号
                                        .cityLimit(true)
                                        .pageCapacity(10)
                                        .scope(2));
                                break;
                            case R.id.fanwei:
                                String fenleis = edit_fanwei.getText().toString();
                                if (check == 0) {
                                    Toast.makeText(this, "请选择范围", Toast.LENGTH_SHORT).show();
                                    return;
                                }
                                com.baidu.mapapi.model.LatLng latLng = new com.baidu.mapapi.model.LatLng(lp.getLatitude(), lp.getLongitude());

                                // 配置请求参数
                                PoiNearbySearchOption nearbySearchOption = new PoiNearbySearchOption()
                                        .keyword(fenleis) // 检索关键字
                                        .location(latLng) // 经纬度
                                        .radius(check) // 检索半径 单位： m
                                        .pageNum(page) // 分页编号
                                        .radiusLimit(true)
                                        .pageCapacity(10)
                                        .scope(2);
                                // 发起检索
                                mPoiSearch.searchNearby(nearbySearchOption);
                                break;
                            default:
                        }
                        break;
                    case 3:
                        switch (sourceCheck.getCheckedRadioButtonId()) {
                            case R.id.quantu:
                                s = editQuantu.getText().toString();
                                if (s == null || s.equals("")) {
                                    Toast.makeText(this, "请输入关键字", Toast.LENGTH_SHORT).show();
                                    return;
                                }

                                break;
                            case R.id.fenlei:
                                String fenlei = textFhang.getText().toString();
                                if (fenlei == null || fenlei.equals("")) {
                                    Toast.makeText(this, "请选择行业", Toast.LENGTH_SHORT).show();
                                    return;
                                }

                                break;
                            case R.id.fanwei:
                                String fenleis = edit_fanwei.getText().toString();
                                if (check == 0) {
                                    Toast.makeText(this, "请选择范围", Toast.LENGTH_SHORT).show();
                                    return;
                                }

                                break;
                            default:
                        }
                        break;
                    default:
                }

            }


            return;
        }

        if (result.error == SearchResult.ERRORNO.AMBIGUOUS_KEYWORD) {
            // 当输入关键字在本市没有找到，但在其他城市找到时，返回包含该关键字信息的城市列表
            String strInfo = "在";

            for (CityInfo cityInfo : result.getSuggestCityList()) {
                strInfo += cityInfo.city;
                strInfo += ",";
            }
            strInfo += "找到结果";
            Toast.makeText(this, strInfo, Toast.LENGTH_LONG).show();
        }
    }

    @Override
    public void onGetPoiDetailResult(PoiDetailResult poiDetailResult) {

    }

    @Override
    public void onGetPoiDetailResult(PoiDetailSearchResult poiDetailSearchResult) {

    }

    @Override
    public void onGetPoiIndoorResult(PoiIndoorResult poiIndoorResult) {

    }

    @Override
    public void onGetSuggestionResult(SuggestionResult suggestionResult) {

    }

    @Override
    public void getChildrenLocation(com.baidu.mapapi.model.LatLng childrenLocation) {

    }

    @Override
    public void onMapLongClick(com.tencent.tencentmap.mapsdk.maps.model.LatLng latLng) {
       Location location = new Location("LongPressLocationProvider");
        location.setLatitude(latLng.latitude);
        location.setLongitude(latLng.longitude);
        location.setAccuracy(20);
        locationChangedListener.onLocationChanged(location);
        Log.i("long click", new Gson().toJson(latLng));
    }

    @Override
    public void onLocationChanged(TencentLocation tencentLocation, int i, String s) {

        if (i == TencentLocation.ERROR_OK && locationChangedListener != null) {
            Location location = new Location(tencentLocation.getProvider());
            //设置经纬度以及精度
            location.setLatitude(tencentLocation.getLatitude());
            location.setLongitude(tencentLocation.getLongitude());
            location.setAccuracy(tencentLocation.getAccuracy());
            locationChangedListener.onLocationChanged(location);

            //显示回调的实时位置信息
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    //打印tencentLocation的json字符串
//                    Toast.makeText(getApplicationContext(), new Gson().toJson(location), Toast.LENGTH_LONG).show();
                }
            });
        }
    }

    @Override
    public void onStatusUpdate(String s, int i, String s1) {

    }

    private class myPoiOverlay {
        private AMap mamap;
        private List<PoiItem> mPois;
        private ArrayList<Marker> mPoiMarks = new ArrayList<Marker>();

        public myPoiOverlay(AMap amap, List<PoiItem> pois) {
            mamap = amap;
            mPois = pois;
        }

        /**
         * 添加Marker到地图中。
         *
         * @since V2.1.0
         */
        public void addToMap() {
            for (int i = 0; i < mPois.size(); i++) {
                Marker marker = mamap.addMarker(getMarkerOptions(i));
                PoiItem item = mPois.get(i);
                marker.setObject(item);
                mPoiMarks.add(marker);
            }
        }

        /**
         * 去掉PoiOverlay上所有的Marker。
         *
         * @since V2.1.0
         */
        public void removeFromMap() {
            for (Marker mark : mPoiMarks) {
                mark.remove();
            }
        }

        /**
         * 移动镜头到当前的视角。
         *
         * @since V2.1.0
         */
        public void zoomToSpan() {
            if (mPois != null && mPois.size() > 0) {
                if (mamap == null) {
                    return;
                }
                LatLngBounds bounds = getLatLngBounds();
                mamap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 100));
            }
        }

        private LatLngBounds getLatLngBounds() {
            LatLngBounds.Builder b = LatLngBounds.builder();
            for (int i = 0; i < mPois.size(); i++) {
                b.include(new LatLng(mPois.get(i).getLatLonPoint().getLatitude(),
                        mPois.get(i).getLatLonPoint().getLongitude()));
            }
            return b.build();
        }

        private MarkerOptions getMarkerOptions(int index) {
            return new MarkerOptions()
                    .position(
                            new LatLng(mPois.get(index).getLatLonPoint()
                                    .getLatitude(), mPois.get(index)
                                    .getLatLonPoint().getLongitude()))
                    .title(getTitle(index)).snippet(getSnippet(index))
                    .icon(getBitmapDescriptor(index));
        }

        protected String getTitle(int index) {
            return mPois.get(index).getTitle();
        }

        protected String getSnippet(int index) {
            return mPois.get(index).getSnippet();
        }

        /**
         * 从marker中得到poi在list的位置。
         *
         * @param marker 一个标记的对象。
         * @return 返回该marker对应的poi在list的位置。
         * @since V2.1.0
         */
        public int getPoiIndex(Marker marker) {
            for (int i = 0; i < mPoiMarks.size(); i++) {
                if (mPoiMarks.get(i).equals(marker)) {
                    return i;
                }
            }
            return -1;
        }

        /**
         * 返回第index的poi的信息。
         *
         * @param index 第几个poi。
         * @return poi的信息。poi对象详见搜索服务模块的基础核心包（com.amap.api.services.core）中的类 <strong><a href="../../../../../../Search/com/amap/api/services/core/PoiItem.html" title="com.amap.api.services.core中的类">PoiItem</a></strong>。
         * @since V2.1.0
         */
        public PoiItem getPoiItem(int index) {
            if (index < 0 || index >= mPois.size()) {
                return null;
            }
            return mPois.get(index);
        }

        protected BitmapDescriptor getBitmapDescriptor(int arg0) {
            if (arg0 < 10) {
                BitmapDescriptor icon = BitmapDescriptorFactory.fromBitmap(
                        BitmapFactory.decodeResource(getResources(), markers[arg0]));
                return icon;
            } else {
                BitmapDescriptor icon = BitmapDescriptorFactory.fromBitmap(
                        BitmapFactory.decodeResource(getResources(), R.drawable.poi_marker));
                return icon;
            }
        }


    }


    /**
     * ArrayList<Houtai> list=new ArrayList<>();
     * <p>
     * <p>
     * for (int i=0;i<pois.size()&&i<3;i++){
     * PoiItem poiItem = pois.get(i);
     * String adCode = poiItem.getAdCode();
     * String tel = poiItem.getTel();//固定电话
     * String adName = poiItem.getAdName();//海淀区
     * String businessArea = poiItem.getBusinessArea();
     * String cityCode = poiItem.getCityCode();
     * String cityName = poiItem.getCityName();//北京市
     * String direction = poiItem.getDirection();
     * int distance = poiItem.getDistance();
     * String email = poiItem.getEmail();
     * LatLonPoint enter = poiItem.getEnter();
     * LatLonPoint exit = poiItem.getExit();
     * IndoorData indoorData = poiItem.getIndoorData();
     * LatLonPoint latLonPoint = poiItem.getLatLonPoint();//经纬度位置
     * String parkingType = poiItem.getParkingType();
     * List<Photo> photos = poiItem.getPhotos();
     * String poiId = poiItem.getPoiId();
     * String postcode = poiItem.getPostcode();
     * String provinceCode = poiItem.getProvinceCode();
     * String provinceName = poiItem.getProvinceName();
     * String shopID = poiItem.getShopID();
     * String snippet = poiItem.getSnippet();//地址
     * String title = poiItem.getTitle();//肯德基（板井路店）
     * String typeCode = poiItem.getTypeCode();
     * String typeDes = poiItem.getTypeDes();//店铺类型：餐饮服务；快餐厅；肯德基
     * String website = poiItem.getWebsite();
     * <p>
     * //            Toast.makeText(this, adCode, Toast.LENGTH_SHORT).show();
     * //            Log.i("asCode",adCode);
     * <p>
     * Houtai houtai = new Houtai();
     * houtai.setSnippet(snippet);
     * houtai.setTel(tel);
     * houtai.setTitle(title);
     * <p>
     * list.add(houtai);
     * <p>
     * }
     * <p>
     * String s = new Gson().toJson(list);
     * <p>
     * Log.i("返回给后台的json",s);
     */


    private void initJsonData() {
        String JsonData = new GetJsonDataUtil().getJson(this, "full.json");//获取assets目录下的json文件数据

//        ArrayList<PoiProvince> jsonBean1 = parseData(JsonData);//用Gson 转成实体

        PoiProvince jsonBean2=new Gson().fromJson(JsonData,PoiProvince.class);

        List<PoiProvince.DataBean> jsonBean = jsonBean2.getData();

        /**
         * 添加省份数据
         *
         * 注意：如果是添加的JavaBean实体，则实体类需要实现 IPickerViewData 接口，
         * PickerView会通过getPickerViewText方法获取字符串显示出来。
         */
        options1Items = jsonBean;

        for (int i = 0; i < jsonBean.size(); i++) {//遍历省份
            optionshItems.add(jsonBean.get(i).getName());

            ArrayList<String> CityList = new ArrayList<>();//该省的城市列表（第二级）
            ArrayList<ArrayList<String>> Province_AreaList = new ArrayList<>();//该省的所有地区列表（第三级）

            for (int c = 0; c < jsonBean.get(i).getChildren().size(); c++) {//遍历该省份的所有城市
                String CityName = jsonBean.get(i).getChildren().get(c).getName();
                CityList.add(CityName);//添加城市
                ArrayList<String> City_AreaList = new ArrayList<>();//该城市的所有地区列表

                //如果无地区数据，建议添加空字符串，防止数据为null 导致三个选项长度不匹配造成崩溃
                if (jsonBean.get(i).getChildren().get(c).getName() == null || jsonBean.get(i).getChildren().get(c).getChildren().size() == 0) {
                    City_AreaList.add("");
                } else {
                    for (int j = 0; j < jsonBean.get(i).getChildren().get(c).getChildren().size(); j++) {
                        City_AreaList.add(jsonBean.get(i).getChildren().get(c).getChildren().get(j).getName());
                    }
                }
                Province_AreaList.add(City_AreaList);//添加该省所有地区数据
            }

            /**
             * 添加城市数据
             */
            options2Items.add(CityList);

            /**
             * 添加地区数据
             */
            options3Items.add(Province_AreaList);
        }
    }

    public ArrayList<PoiProvince> parseData(String result) {//Gson 解析
        ArrayList<PoiProvince> detail = new ArrayList<>();
        detail.clear();
        Gson gson = new GsonBuilder().setLenient().create();
        detail = gson.fromJson(result, new TypeToken<List<PoiProvince>>() {
        }.getType());

        return detail;
    }


    private int check = 0;

    private PopupWindow popWindow;

    private void showPopwindow() {
        View popView = View.inflate(this, R.layout.popup_juli, null);
        ImageView cancle = popView.findViewById(R.id.cancle);
        Button sure = popView.findViewById(R.id.sure);
        final RadioGroup group = popView.findViewById(R.id.group);

        sure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                switch (group.getCheckedRadioButtonId()) {
                    case R.id.five:
                        check = 5000;
                        textFjuli.setText("5km");
                        break;
                    case R.id.ten:
                        check = 10000;
                        textFjuli.setText("10km");
                        break;
                    default:
                }
                popWindow.dismiss();

            }
        });

        cancle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                popWindow.dismiss();
            }
        });

        popWindow = new PopupWindow(popView, ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, true);
        popWindow.setFocusable(true);
        popWindow.setTouchable(true);
        popWindow.setBackgroundDrawable(new BitmapDrawable());
        popWindow.setOutsideTouchable(true);// 设置允许在外点击消失

        popWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                // popupWindow隐藏时恢复屏幕正常透明度
                setBackgroundAlpha(1.0f);
            }
        });

    }


    private PopupWindow popupWindows;

    private void showPopwindows() {
        View popView = View.inflate(this, R.layout.popup_hang, null);
        TextView sure = popView.findViewById(R.id.sure);
        EditText search = popView.findViewById(R.id.search);
        RecyclerView recy_hot = popView.findViewById(R.id.recy_hot);
        RecyclerView recy_all = popView.findViewById(R.id.recy_all);

        GridLayoutManager manager = new GridLayoutManager(this, 4);
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        GridLayoutManager managers = new GridLayoutManager(this, 4);
        managers.setOrientation(LinearLayoutManager.VERTICAL);
        recy_hot.setLayoutManager(manager);
        recy_all.setLayoutManager(managers);
        final TradesAdapter adapter = new TradesAdapter(this);
        final TradesAdapter adapters = new TradesAdapter(this);
        adapter.setdeleteClick(new TradesAdapter.OnClick() {
            @Override
            public void item(int posttion) {
                for (int i = 0; i < getTradesBean.size(); i++) {
                    if (i == posttion) {
                        getTradesBean.get(i).setParam_check("1");
                    } else {
                        getTradesBean.get(i).setParam_check("0");
                    }
                }
                for (int i = 0; i < getTradesBeans.size(); i++) {
                    getTradesBeans.get(i).setParam_check("0");
                }


                adapter.setList(getTradesBean);
                adapters.setList(getTradesBeans);
            }
        });
        adapters.setdeleteClick(new TradesAdapter.OnClick() {
            @Override
            public void item(int posttion) {
                for (int i = 0; i < getTradesBean.size(); i++) {
                    getTradesBean.get(i).setParam_check("0");
                }
                for (int i = 0; i < getTradesBeans.size(); i++) {
                    if (i == posttion) {
                        getTradesBeans.get(i).setParam_check("1");
                    } else {
                        getTradesBeans.get(i).setParam_check("0");
                    }
                }

                adapter.setList(getTradesBean);
                adapters.setList(getTradesBeans);
            }
        });

        recy_hot.setAdapter(adapter);
        recy_all.setAdapter(adapters);

        adapter.setList(getTradesBean);
        adapters.setList(getTradesBeans);

        sure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                boolean check = false;
                for (int i = 0; i < getTradesBean.size(); i++) {
                    if (getTradesBean.get(i).getParam_check().equals("1")) {
                        textFhang.setText(getTradesBean.get(i).getTradeName());
                        textHang.setText(getTradesBean.get(i).getTradeName());
                        check = true;
                    }
                }
                for (int i = 0; i < getTradesBeans.size(); i++) {
                    if (getTradesBeans.get(i).getParam_check().equals("1")) {
                        textFhang.setText(getTradesBeans.get(i).getTradeName());
                        textHang.setText(getTradesBeans.get(i).getTradeName());
                        check = true;
                    }
                }
                if (!check) {
                    Toast.makeText(MapsActivity.this, "请选择行业", Toast.LENGTH_SHORT).show();
                } else {
                    popupWindows.dismiss();
                }
            }
        });

        popupWindows = new PopupWindow(popView, ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, true);
        popupWindows.setFocusable(true);
        popupWindows.setTouchable(true);
        popupWindows.setBackgroundDrawable(new BitmapDrawable());
        popupWindows.setOutsideTouchable(true);// 设置允许在外点击消失

        popupWindows.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                // popupWindow隐藏时恢复屏幕正常透明度
                setBackgroundAlpha(1.0f);
            }
        });

    }


    /**
     * 设置添加屏幕的背景透明度
     *
     * @param bgAlpha 屏幕透明度0.0-1.0 1表示完全不透明
     */
    public void setBackgroundAlpha(float bgAlpha) {
        WindowManager.LayoutParams lp = getWindow()
                .getAttributes();
        lp.alpha = bgAlpha;
        getWindow().setAttributes(lp);
    }

    protected class MyPoiOverlays extends PoiOverlay {
        MyPoiOverlays(BaiduMap baiduMap) {
            super(baiduMap);
        }

        @Override
        public boolean onPoiClick(int index) {
            super.onPoiClick(index);
            PoiInfo poi = getPoiResult().getAllPoi().get(index);
            Toast.makeText(MapsActivity.this, poi.address, Toast.LENGTH_LONG).show();
            return true;
        }
    }



    protected void searchPoiquantu(final String s) {
        TencentSearch tencentSearch = new TencentSearch(this);
//        String keyWord = etSearch.getText().toString().trim();
        //城市搜索
        SearchParam.Region region = new SearchParam.Region(city+area).//设置搜索城市
                autoExtend(false);//设置搜索范围不扩大
        //圆形范围搜索
        com.tencent.tencentmap.mapsdk.maps.model.LatLng latLng1 = new com.tencent.tencentmap.mapsdk.maps.model.LatLng(lp.getLatitude(), lp.getLongitude());
        SearchParam.Nearby nearBy = new SearchParam.Nearby(latLng1, 1000);
        //filter()方法可以设置过滤类别，
        //search接口还提供了排序方式、返回条目数、返回页码具体用法见文档，
        //同时也可以参考官网的webservice对应接口的说明
        SearchParam searchParam = new SearchParam(s, region);//.pageIndex(0).pageSize(20).filter("大学,中学");
        searchParam.pageIndex(page);
        searchParam.pageSize(20);
        tencentSearch.search(searchParam, new HttpResponseListener<BaseObject>() {

            @Override
            public void onFailure(int arg0, String arg2,
                                  Throwable arg3) {
                dissmissProgressDialog();
//                Toast.makeText(getApplicationContext(), arg2, Toast.LENGTH_LONG).show();
            }

            @Override
            public void onSuccess(int arg0, BaseObject arg1) {

                if (!isPOI){
                    return;
                }

                if (arg1 == null) {
                    dissmissProgressDialog();
                    return;
                }

                SearchResultObject obj = (SearchResultObject) arg1;
                if(obj.data == null){
                    dissmissProgressDialog();
                    return;
                }

                if(obj.data.size() == 0){
                    dissmissProgressDialog();
                    return;
                }

                if (page==1){
                    tencentMap.clear();
                    num=0;
                }

                for (int i = 0; i < obj.data.size(); i++) {
                    if (obj.data.get(i).tel==null||obj.data.get(i).tel.equals("")){
                        obj.data.remove(i);
                        i--;
                    }
                }

//                tencentMap.moveCamera(com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory.newCameraPosition(new CameraPosition(obj.data.get(0).latLng,15f, 0, 0)));
                for(SearchResultObject.SearchResultData data : obj.data){
                    Log.v("SearchDemo","title:"+data.title + ";" + data.address);
                    tencentMap.addMarker(new com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions()
                            .position(data.latLng)  //标注的位置
                            .title(data.title)     //标注的InfoWindow的标题
                            .snippet(data.address) //标注的InfoWindow的内容
                    );

                }

                ArrayList<Houtai> list = new ArrayList<>();

                for (int i = 0; i < obj.data.size(); i++) {
                    SearchResultObject.SearchResultData poiItem = obj.data.get(i);
                    //固定电话
                    String tel = poiItem.tel;
                    //地址
                    String snippet = poiItem.address;
                    //肯德基（板井路店）
                    String title = poiItem.title;

                    String[] split = tel.split(";");
                    for (int j = 0; j < split.length; j++) {

                        Houtai houtai = new Houtai();
                        houtai.setSnippet(snippet);
                        houtai.setTel(split[j]);
                        houtai.setTitle(title);
                        houtai.setSource("1");
                        list.add(houtai);
                    }
                }
                String json = new Gson().toJson(list);
                Map<String, String> map = new HashMap<>();
                map.put("token", Constant.TOKEN);
                map.put("customer_type", findtype + "");
                map.put("collect_data", json);
                map.put("uid", uid);
                map.put("province", province);
                map.put("city", city);
                map.put("area", area);

                switch (sourceCheck.getCheckedRadioButtonId()) {
                    case R.id.quantu:
                        String ss = editQuantu.getText().toString();
                        map.put("search_key", ss);
                        break;
                    case R.id.fenlei:
                        String fenlei = textFhang.getText().toString();
                        map.put("industry", fenlei);
                        break;
                    case R.id.fanwei:
                        String fenleis = edit_fanwei.getText().toString();//check
                        map.put("search_key", fenleis);
                        map.put("distance", check + "");
                        break;
                    default:
                }
                pressenter.sendMessage(MapsActivity.this, Constant.customercollectadd, map, Bean.class);


                num=num+obj.data.size();

                getNum.setText("本次共获客"+num+"条");
                page++;
                searchPoiquantu(s);

            }
        });
    }
    protected void searchPoifanwei(final String s) {
        TencentSearch tencentSearch = new TencentSearch(this);
//        String keyWord = etSearch.getText().toString().trim();
        //城市搜索
        SearchParam.Region region = new SearchParam.Region(province+city+area).//设置搜索城市
                autoExtend(false);//设置搜索范围不扩大
        //圆形范围搜索
        com.tencent.tencentmap.mapsdk.maps.model.LatLng latLng1 = new com.tencent.tencentmap.mapsdk.maps.model.LatLng(lp.getLatitude(), lp.getLongitude());
        SearchParam.Nearby nearBy = new SearchParam.Nearby(latLng1, check);
        //filter()方法可以设置过滤类别，
        //search接口还提供了排序方式、返回条目数、返回页码具体用法见文档，
        //同时也可以参考官网的webservice对应接口的说明
        SearchParam searchParam = new SearchParam(s, nearBy);//.pageIndex(0).pageSize(20).filter("大学,中学");
        searchParam.pageIndex(page);
        searchParam.pageSize(20);
        tencentSearch.search(searchParam, new HttpResponseListener<BaseObject>() {

            @Override
            public void onFailure(int arg0, String arg2,
                                  Throwable arg3) {
                dissmissProgressDialog();
//                Toast.makeText(getApplicationContext(), arg2, Toast.LENGTH_LONG).show();
            }

            @Override
            public void onSuccess(int arg0, BaseObject arg1) {
                if (!isPOI){
                    return;
                }
                if (arg1 == null) {
                    dissmissProgressDialog();
                    return;
                }
                SearchResultObject obj = (SearchResultObject) arg1;
                if(obj.data == null){
                    dissmissProgressDialog();
                    return;
                }


                if (page==1){
                    tencentMap.clear();
                    num=0;
                }

                for (int i = 0; i < obj.data.size(); i++) {
                    if (obj.data.get(i).tel==null||obj.data.get(i).tel.equals("")){
                        obj.data.remove(i);
                        i--;
                    }
                }

                tencentMap.moveCamera(com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory.newCameraPosition(new CameraPosition(obj.data.get(0).latLng,15f, 0, 0)));
                for(SearchResultObject.SearchResultData data : obj.data){
                    Log.v("SearchDemo","title:"+data.title + ";" + data.address);
                    tencentMap.addMarker(new com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions()
                            .position(data.latLng)  //标注的位置
                            .title(data.title)     //标注的InfoWindow的标题
                            .snippet(data.address) //标注的InfoWindow的内容
                    );

                }

                ArrayList<Houtai> list = new ArrayList<>();

                for (int i = 0; i < obj.data.size(); i++) {
                    SearchResultObject.SearchResultData poiItem = obj.data.get(i);
                    //固定电话
                    String tel = poiItem.tel;
                    //地址
                    String snippet = poiItem.address;
                    //肯德基（板井路店）
                    String title = poiItem.title;

                    String[] split = tel.split(";");
                    for (int j = 0; j < split.length; j++) {

                        Houtai houtai = new Houtai();
                        houtai.setSnippet(snippet);
                        houtai.setTel(split[j]);
                        houtai.setTitle(title);
                        houtai.setSource("1");
                        list.add(houtai);
                    }

                }
                String json = new Gson().toJson(list);
                Map<String, String> map = new HashMap<>();
                map.put("token", Constant.TOKEN);
                map.put("customer_type", findtype + "");
                map.put("collect_data", json);
                map.put("uid", uid);
                map.put("province", province);
                map.put("city", city);
                map.put("area", area);

                switch (sourceCheck.getCheckedRadioButtonId()) {
                    case R.id.quantu:
                        String ss = editQuantu.getText().toString();
                        map.put("search_key", ss);
                        break;
                    case R.id.fenlei:
                        String fenlei = textFhang.getText().toString();
                        map.put("industry", fenlei);
                        break;
                    case R.id.fanwei:
                        String fenleis = edit_fanwei.getText().toString();//check
                        map.put("search_key", fenleis);
                        map.put("distance", check + "");
                        break;
                    default:
                }
                pressenter.sendMessage(MapsActivity.this, Constant.customercollectadd, map, Bean.class);


                num=num+obj.data.size();

                getNum.setText("本次共获客"+num+"条");
                page++;
                searchPoifanwei(s);

            }
        });
    }

}